<template>
<h2>会员权益列表展示</h2>

<input type="text" v-model="nnn">

<select v-model="ccc">
    <option  :value="0">请选择</option>
    <option :value="1">是</option>
    <option :value="2">否</option>
</select>

<input type="button" value="搜索" @click="SouSuo">


<table  class="table table-bordered">
    <thead>

            <tr>
                <th>会员权益编号</th>
                <th>会员权益名称</th>
                <th>会员权益说明</th>
                <th>是否自定义</th>
                <th>规则类型</th>
                <th>权益规则</th>
                <th>操作</th>
            </tr>

    </thead>

    <tbody>
            <tr v-for="item in info">
                <th>{{ item.MR_Id }}</th>
                <th>{{ item.MR_Name }}</th>
                <th>{{ item. MR_Info}}</th>
                <th>{{ item.MR_IsCustion=="true"?"是":"否"}}</th>
                <th>{{ item.MR_RuleType }}</th>
                <th>{{ item.MR_Rule }}</th>
                <th>
                    <a href="#" @click="Xg(item.MR_Id)">修改</a>   
                    <a href="#" @click="Del(item.MR_Id)">删除</a>
                </th>
            </tr>
    </tbody>


</table>


</template>
<script setup lang="ts">
import { onMounted,ref } from 'vue';
import axios from 'axios';
import {useRouter,createRouter} from 'vue-router'


const nnn =ref('');
const ccc =ref(0)

const router= useRouter();

const SouSuo=()=>{
    ShowMe();
    

}


//创建响应式数据


const info=ref([{

    MR_Id:0,
    MR_Info:"",
    MR_IsCustion:"",
    MR_Name:"",
    MR_Rule:"",
    MR_RuleType:0,



}])
 //创建onmounted 注册周期钩子 页面在加载时运行的函数
onMounted(()=>{
    ShowMe();

});


const ShowMe=()=>{  //显示
   
    axios.get('https://localhost:7035/api/Member/ShowMe',{

        params:{


            Name:nnn.value,
            Type1:ccc.value
        }

    })
    .then(res=>{
      

    

            info.value=res.data;
         
 
    })
    .catch(error=>{

            console.log(error);

    })



}



const Xg=(MR_Id:number)=>{   //修改跳转




 router.push({
    name:"Xg",
    params:{
        MRid:MR_Id
    }
    



 });

}


const Del=(MR_Id:number)=>{
   
   if(!confirm('确认删除吗'))
{
    return ; 
    
}
    axios.delete('https://localhost:7035/api/Member/DelMe?id='+MR_Id).then(res=>{

      
            if(res.data>0)
            {
                alert('删除成功')
                ShowMe();
            }
            else
            {
                alert('删除失败')
            }
    })
    .catch(error=>{
     alert(error);
        console.log(error);

    })


}

</script>